//
//  TQYWebSocket.h
//  TQY
//
//  Created by 甘世清 on 2024/10/25.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN
/**
 *  @author SQ
 *
 *  socket状态
 */
typedef NS_ENUM(NSInteger,SQSocketStatus){
    SQSocketStatusConnected,// 已连接
    SQSocketStatusFailed,// 失败
    SQSocketStatusClosedByServer,// 系统关闭
    SQSocketStatusClosedByUser,// 用户关闭
    SQSocketStatusReceived// 接收消息
};
/**
 *  @author SQ
 *
 *  消息类型
 */
typedef NS_ENUM(NSInteger,SQSocketReceiveType){
    SQSocketReceiveTypeForMessage,
    SQSocketReceiveTypeForPong
};
/**
 *  @author SQ
 *
 *  连接成功回调
 */
typedef void(^SQSocketDidConnectBlock)(void);
/**
 *  @author SQ
 *
 *  发送成功回调
 */
typedef void(^SQSocketDidSendBlock)(BOOL isSend);
/**
 *  @author SQ
 *
 *  失败回调
 */
typedef void(^SQSocketDidFailBlock)(NSError *error);
/**
 *  @author SQ
 *
 *  关闭回调
 */
typedef void(^SQSocketDidCloseBlock)(NSInteger code,NSString *reason,BOOL wasClean);
/**
 *  @author SQ
 *
 *  消息接收回调
 */
typedef void(^SQSocketDidReceiveBlock)(id message ,SQSocketReceiveType type);

@interface TQYWebSocket : NSObject
/**
 *  @author SQ
 *
 *  连接回调
 */
@property (nonatomic,copy)SQSocketDidConnectBlock connect;
/**
 *  @author SQ
 *
 *  接收消息回调
 */
@property (nonatomic,copy)SQSocketDidReceiveBlock receive;
/**
 *  @author SQ
 *
 *  失败回调
 */
@property (nonatomic,copy)SQSocketDidFailBlock failure;
/**
 *  @author SQ
 *
 *  关闭回调
 */
@property (nonatomic,copy)SQSocketDidCloseBlock close;
/**
 *  @author SQ
 *
 *  当前的socket状态
 */
@property (nonatomic,assign,readonly)SQSocketStatus SQ_socketStatus;
/**
 *  @author SQ
 *
 *  超时重连时间，默认1秒
 */
@property (nonatomic,assign)NSTimeInterval overtime;
/**
 *  @author Clarence
 *
 *  重连次数,默认5次
 */
@property (nonatomic, assign)NSUInteger reconnectCount;
/**
 *  @author SQ
 *
 *  单例调用
 */
+ (instancetype)shareManager;
/**
 *  @author SQ
 *
 *  开启socket
 *
 *  @param urlStr  服务器地址
 *  @param connect 连接成功回调
 *  @param receive 接收消息回调
 *  @param failure 失败回调
 */
- (void)SQ_open:(NSString *)urlStr connect:(SQSocketDidConnectBlock)connect receive:(SQSocketDidReceiveBlock)receive failure:(SQSocketDidFailBlock)failure;
/**
 *  @author SQ
 *
 *  关闭socket
 *
 *  @param close 关闭回调
 */
- (void)SQ_close:(SQSocketDidCloseBlock)close;
/**
 *  @author SQ
 *
 *  发送消息，NSString 或者 NSData
 *
 *  @param data Send a UTF8 String or Data.
 */
- (void)SQ_send:(id)data isSend:(SQSocketDidSendBlock)sendBlock;

-(void)SQ_reconnect;

@end

NS_ASSUME_NONNULL_END
